<?php

App::uses('AppController', 'Controller');

class CheckerController extends AppController {

    public function beforeFilter() {
        $this->Auth->allow();
    }

    public function index($id = '') {
        $appBosch = new stdClass();       
        $appBosch->idToCheck = $id;
        $this->set('appBosch', $appBosch);
        $this->set('title', __('Verificador de firma digital'));
    }
    
    public function verify($id) {
        $type = null;
        $nRecord = null;
        $this->layout = null;
        $this->loadModel('Passport');
        $this->loadModel('Certificate');
        $this->loadModel('Diploma');
        $res = $this->Passport->findById($id);
        if (count($res) != 0 ) {
            $nRecord = $res['Passport'];
            $nRecord['data'] = json_decode($nRecord['data']);
            $type = 'passport';
        } else {
            $res = $this->Certificate->findById($id);
            if (count($res) != 0 ) {
                $nRecord = $res['Certificate'];
                $nRecord['data'] = json_decode($nRecord['data']);
                $type = 'certificate';
            } else {
                $res = $this->Diploma->findById($id);
                if (count($res) != 0 ) {
                    $nRecord = $res['Certificate'];
                    $nRecord['data'] = json_decode($nRecord['data']);
                    $type = 'diploma';
                }
            }
        }
        $this->set('type', $type);
        $this->set('record', $nRecord);
    }
}